package data;


/**
 * This class manages data, methods, and fields relevant to a Volunteer object.
 * This class extends User and implements Comparable.
 * 
 * @author Stephen Amos
 */
public class Volunteer extends User implements Comparable<Volunteer> {
	
	/**
	 * The first name of the Volunteer.
	 * i.e. If a volunteer's name was John Doe, "John" would be the value for
	 * firstname.
	 */
	private String firstname;
	
	/**
	 * The last name of the Volunteer.
	 * i.e. If a volunteer's name was John Doe, "Doe" would be the value for
	 * surname.
	 */
	private String surname;
	
	/**
	 * The date of birth of the Volunteer, stored in the form of a String object.
	 */
	private String dob;
	
	/**
	 * This boolean determines whether a volunteer is a group leader or not.
	 * Note: Only Schedulers may change this field.
	 */
	private boolean isLeader;
	
	/**
	 * This array of strings contains the job history of this Volunteer object.
	 */
	private String[] jobHistory;
	
	/**
	 * This constructor creates a Volunteer object based upon the parameters
	 * passed in.
	 * 
	 * @param name The first name of the volunteer.
	 * @param surname The last name of the volunteer.
	 * @param username The volunteer's username for logging into the system.
	 * @param password The volunteer's password for logging into the system.
	 * @param phone The volunteer's phone number.
	 * @param email The volunteer's e-mail address.
	 * @param dob The volunteer's date of birth.
	 */
	public Volunteer(String name, String surname, String username, 
			String password, String phone, String email, String dob) {
		super(username, password, phone, email);
		this.firstname = name;
		this.surname = surname;
		this.dob = dob;
		isLeader = false;
	}
	
	/**
	 * This constructor creates a Volunteer object based upon the parameters
	 * passed in. It should only be used for loading data.
	 * 
	 * @param name The first name of the volunteer.
	 * @param surname The last name of the volunteer.
	 * @param username The volunteer's username for logging into the system.
	 * @param password The volunteer's password for logging into the system.
	 * @param phone The volunteer's phone number.
	 * @param email The volunteer's e-mail address.
	 * @param dob The volunteer's date of birth.
	 * @param groupLeader The Volunteer's group leader status.
	 */
	public Volunteer(String name, String surname, String username, 
			String password, String phone, String email, String dob, boolean groupLeader) {
		super(username, password, phone, email);
		this.firstname = name;
		this.surname = surname;
		this.dob = dob;
		isLeader = groupLeader;
	}
	
	/**
	 * Allows the volunteer to sign up for a job.
	 * 
	 * @param job The job the user wishes to volunteer in.
	 */
	public void signUp(Job job) {
	//	job.addVolunteer(this);
	}

	/**
	 * Allows the volunteer to sign up for a job as a group leader.
	 * 
	 * @param job The job the user wishes to volunteer in.
	 */
	public void signUpAsLeader(Job job) {
	//	job.addVolunteer(this);
	}

	/**
	 * Determines whether this particular Volunteer object is the same as another
	 * object passed in.
	 * 
	 * @param x The object to be tested for equality.
	 */
	public boolean equals(Object x) {
		if (x != null && x instanceof Volunteer && this.username != null) {
			String temp = ((Volunteer) x).getUsername();
			if (temp != null && !temp.trim().equals("") && this.username.equalsIgnoreCase(temp)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * Returns the first name of this Volunteer object.
	 * 
	 * @return The first name of this volunteer object.
	 */
	public String getFirstname() {
		return firstname;
	}

	/**
	 * Sets the first name of this Volunteer object based upon the parameter
	 * passed in.
	 * 
	 * @param firstname The new first name to be set to this Volunteer object.
	 */
	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	/**
	 * Gets the surname of this Volunteer object.
	 * 
	 * @return The surname of this Volunteer object.
	 */
	public String getSurname() {
		return surname;
	}

	/**
	 * Sets the surname of this Volunteer object based upon the parameter 
	 * passed in.
	 * 
	 * @param surname The new surname to be set to this Volunteer object.
	 */
	public void setSurname(String surname) {
		this.surname = surname;
	}

	/**
	 * Returns the date of birth of this Volunteer.
	 * 
	 * @return The date of birth of this Volunteer.
	 */
	public String getDob() {
		return dob;
	}

	/**
	 * Sets the date of birth of this Volunteer.
	 * 
	 * @param dob The new date of birth to be set to this Volunteer.
	 */
	public void setDob(String dob) {
		this.dob = dob;
	}

	/**
	 * Returns a boolean based upon whether this particular Volunteer object
	 * is flagged as a Group Leader.  If this Volunteer object is not a group leader,
	 * a value of False is returned.
	 * 
	 * @return A boolean that is true if, and only if the Volunteer is a group
	 * leader.
	 */
	public boolean isLeader() {
		return isLeader;
	}

	/**
	 * Sets a Volunteer's group leader status based upon the parameter passed in.
	 * 
	 * @param isLeader Sets this Volunteer's group leader status to either false
	 * or true.
	 */
	public void setLeader(boolean isLeader) {
		this.isLeader = isLeader;
	}

	/**
	 * Returns the history of jobs of this Volunteer object.
	 * 
	 * @return The history of jobs of this Volunteer object.
	 */
	public String[] getJobHistory() {
		return jobHistory;
	}

	/**
	 * Sets the history of jobs for this Volunteer object based upon the
	 * parameter passed in.
	 * 
	 * @param jobHistory The new history of jobs to be set to this Volunteer.
	 */
	public void setJobHistory(String[] jobHistory) {
		this.jobHistory = jobHistory;
	}

	/**
	 * An over-ridden toString() method which returns a String of all this
	 * Volunteer's fields.
	 * 
	 * @return A string containing all of this Volunteer's fields.
	 */
	public String toString() {
		return firstname + ",," + surname + ",," + username + ",," + password + ",," + 
		phone + ",," + email + ",," + dob.toString() +  ",," + isLeader() + "\n"; 
	}

	/**
	 * This method compares this current Volunteer object with another
	 * Volunteer object based upon the Volunteer's surname.
	 * 
	 * @param other_volunteer The Volunteer object to be compared to.
	 * @return Zero if the Volunteer objects have the same surname field,
	 * a negative value if the compared Volunteer is alphabetically higher,
	 * or a positive value if the compared Volunteer is alphabetically lower.
	 */
	public int compareTo(Volunteer other_volunteer) {
		return this.surname.compareTo(other_volunteer.getSurname());
	}

}
